<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>on-line diagnostics</title>
    <script th:src="@{/static/js/jquery-3.7.0.min.js}" type="application/javascript"></script>
</head>
<body>
    <input type="hidden" th:value="${host}" id="host">
    <table width="100%" border="0">
        <thead>
            <tr>
                <th align="left">
                    <button id="on">开启在线诊断</button>
                    <button id="off">退出在线诊断</button>
                </th>
                <th></th>
                <th align="right">
                    <button id="quit">退出会话</button>
                    <button id="reset">重置插装</button>
                    <button id="shutdown">关闭诊断</button>
                </th>
            </tr>
            <tr>
                <th align="left"><input id="systemId" placeholder="系统ID" value=""/><font color="red">*</font></th>
            </tr>
            <tr>
                <th align="left"><input id="microServiceId" placeholder="服务ID" value=""/><font color="red">*</font></th>
            </tr>
            <tr>
                <th align="left"><input id="sessionId" placeholder="会话ID" value=""/></th>
            </tr>
            <tr>
                <th colspan="3" align="left">
                    <input id="command" placeholder="请输入命令" size="80" value=""/><font color="red">*</font>
                    <button id="sendCommand">发送命令</button>
                    <button id="receiveCommand">接收命令</button>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="3"><textarea id="receive" placeholder="展示命令返回结果" cols="150" rows="26" value=""></textarea></td>
            </tr>
        </tbody>
    </table>
</body>
<script type="text/javascript">
    var host = $("#host").val();
    //开启在线诊断
    $("#on").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        $.get("http://"+host+"/api/dswitch",{systemId:systemIdValue,microServiceId:microServiceIdValue,onoff:1},function(data,status){
            alert(data.message);
        });
    });
    //退出在线诊断
    $("#off").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        $.get("http://"+host+"/api/dswitch",{systemId:systemIdValue,microServiceId:microServiceIdValue,onoff:0},function(data,status){
            alert(data.message);
        });
    });
    //退出会话
    $("#quit").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        var sessionIdValue = $("#sessionId").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        if(sessionIdValue == "") {
            alert("请输入:会话ID!");
            return;
        }
        $.get("http://"+host+"/api/dcmd",{systemId:systemIdValue,microServiceId:microServiceIdValue,line:"quit",sessionId:sessionIdValue},function(data,status){
            alert(data.message);
        });
    });
    //重置插装
    $("#reset").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        $.get("http://"+host+"/api/dcmd",{systemId:systemIdValue,microServiceId:microServiceIdValue,line:"reset"},function(data,status){
            alert(data.message);
        });
    });
    //关闭诊断
    $("#shutdown").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        $.get("http://"+host+"/api/dcmd",{systemId:systemIdValue,microServiceId:microServiceIdValue,line:"shutdown"},function(data,status){
            alert(data.message);
        });
    });
    //发送命令
    $("#sendCommand").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        var sessionIdValue = $("#sessionId").val();
        var commandValue = $("#command").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        if(commandValue == "") {
            alert("请输入:要发送的命令!");
            return;
        }
        $.get("http://"+host+"/api/dcmd",{systemId:systemIdValue,microServiceId:microServiceIdValue,line:commandValue,sessionId:sessionIdValue},function(data,status){
            alert(data.message);
        });
    });
    //接收命令
    $("#receiveCommand").click(function(){
        var systemIdValue = $("#systemId").val();
        var microServiceIdValue = $("#microServiceId").val();
        if(systemIdValue == "" || microServiceIdValue == "") {
            alert("请输入:系统ID和服务ID!");
            return;
        }
        $.get("http://"+host+"/api/dresult",{systemId:systemIdValue,microServiceId:microServiceIdValue},function(data,status){
            $("#receive").val(JSON.stringify(data,null,2));
        },"json");
    });
</script>
</html>